home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / euphor12 / lines.ex < prev    next >
Text File  |  1994-06-18  |  2KB  |  66 lines

  1. -- lines.e
  2. -- show how many lines and characters there are in a file or bunch of files
  3. -- usage: lines.bat files...
  4. -- example: lines *.e
  5.  
  6. constant SCREEN = 1
  7. constant TRUE = 1
  8.  
  9. function scan(integer fileNum) 
  10. -- count lines, non-blank lines, characters
  11.     object line
  12.     integer lines, nb_lines, chars
  13.  
  14.     lines = 0
  15.     nb_lines = 0
  16.     chars = 0
  17.     while TRUE do
  18.     line = gets(fileNum)
  19.     if atom(line) then   
  20.         -- end of file
  21.         return {nb_lines, lines, chars}
  22.     else
  23.         lines = lines + 1
  24.         chars = chars + length(line) + 1  -- add 1 to match dir cmd
  25.         if find(TRUE, line != ' ' and line != '\t' and line != '\n') then
  26.         nb_lines = nb_lines + 1
  27.         end if
  28.     end if
  29.     end while
  30. end function
  31.  
  32. include getnames.e
  33.  
  34. procedure lines()
  35. -- process all files 
  36.     integer fileNum
  37.     sequence count, total_count
  38.     sequence file_names
  39.  
  40.     -- gather file names
  41.     file_names = get_names()
  42.     if length(file_names) = 0 then
  43.     return
  44.     end if
  45.     -- process all files    
  46.     total_count = {0, 0, 0}
  47.     puts(SCREEN, "non-blank-lines   lines   chars\n")
  48.     for i = 1 to length(file_names) do
  49.         fileNum = open(file_names[i], "r")   
  50.         if fileNum = -1 then
  51.             printf(SCREEN, "cannot open %s\n", {file_names[i]})
  52.         else
  53.         count = scan(fileNum)
  54.         total_count = total_count + count
  55.         printf(SCREEN, "       %8d%8d%8d %s\n", count & {file_names[i]})
  56.         close(fileNum)
  57.         end if
  58.     end for
  59.     if length(file_names) > 1 then
  60.     printf(SCREEN, "       %8d%8d%8d total\n", total_count)
  61.     end if
  62. end procedure
  63.  
  64. lines()
  65.  
  66.